package cn.geminis.data.jpa.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

@Getter
@Setter
@MappedSuperclass
public abstract class Person {

    @Id
    @Column(length = 36)
    private String id;

    @Column(nullable = false, length = 256)
    private String name;

    @Column(nullable = false)
    private int age;

    @Column(nullable = false)
    private LocalDateTime birthday;

    @PrePersist
    void createId() {
        if (!StringUtils.hasText(this.id)) {
            this.id = UUID.randomUUID().toString();
        }
    }
}
